// =====================================================================
// <copyright file="ValidationException.cs" author="David R. Guindo">
// 	Copyright (C) 2013. All rights reserved.
// </copyright>
// =====================================================================
// This code is released under the terms of the Apache 2.0 license, 
// http://apache.org/licenses/LICENSE-2.0.html
// =====================================================================

namespace AppBlock.Core.Validations
{
    using System;
    using System.Collections.Generic;
    using System.Collections.ObjectModel;
    using System.Runtime.Serialization;

    /// <summary>
    ///     Exception class to manage deleted entity.
    /// </summary>
    [Serializable]
    public class ValidationException : Exception
    {
        private ICollection<IValidatable> validationErrors;

        /// <summary>
        ///     Initializes a new instance of the <see cref="ValidationException" /> class.
        /// </summary>
        public ValidationException()
        {
        }

        /// <summary>
        ///     Initializes a new instance of the <see cref="ValidationException" /> class.
        /// </summary>
        /// <param name="message"> The message. </param>
        /// <param name="validations"> The validations. </param>
        public ValidationException(string message, IValidation validations)
            : base(message)
        {
            this.validationErrors = validations.Validations;
        }

        /// <summary>
        ///     Initializes a new instance of the <see cref="ValidationException" /> class.
        /// </summary>
        /// <param name="message"> The message. </param>
        /// <param name="inner"> The inner. </param>
        public ValidationException(string message, Exception inner)
            : base(message, inner)
        {
        }

        /// <summary>
        ///     Initializes a new instance of the <see cref="ValidationException" /> class. A constructor is needed for
        ///     serialization when an exception propagates from a remoting server to the client.
        /// </summary>
        /// <param name="info">
        ///     The <see cref="T:System.Runtime.Serialization.SerializationInfo" /> that holds the serialized
        ///     object data about the exception being thrown.
        /// </param>
        /// <param name="context">
        ///     The <see cref="T:System.Runtime.Serialization.StreamingContext" /> that contains contextual
        ///     information about the source or destination.
        /// </param>
        /// <exception cref="T:System.ArgumentNullException">
        ///     The
        ///     <paramref name="info" />
        ///     parameter is null.
        /// </exception>
        /// <exception cref="T:System.Runtime.Serialization.SerializationException">
        ///     The class name is null or
        ///     <see cref="P:System.Exception.HResult" />
        ///     is zero (0).
        /// </exception>
        protected ValidationException(SerializationInfo info, StreamingContext context)
        {
        }

        protected ICollection<IValidatable> ValidationErrors
        {
            get { return this.validationErrors ?? (this.validationErrors = new Collection<IValidatable>()); }
        }
    }
}